_realname=onefetch
pkgbase=mingw-w64-$_realname
pkgname=$MINGW_PACKAGE_PREFIX-$_realname
pkgver=2.14.2
pkgrel=2
pkgdesc="Git repository summary on your terminal (mingw-w64)"
url="https://github.com/o2sh/onefetch"
license=('MIT')
arch=(any)
mingw_arch=(mingw32 mingw64 ucrt64 clang64)
depends=("$MINGW_PACKAGE_PREFIX-libgit2")
makedepends=("$MINGW_PACKAGE_PREFIX-rust"
             "$MINGW_PACKAGE_PREFIX-cmake")
source=("$_realname-$pkgver.tar.gz::$url/archive/$pkgver.tar.gz")
sha256sums=('df5e10aac076369bbbdeb94eef286dbde8d10859fd8f47af7e2748fadef0622c')

prepare() {
  cd "$_realname-$pkgver"
  cargo fetch --locked
  mkdir -p completions
}

build() {
  cd "$_realname-$pkgver"
  WINAPI_NO_BUNDLED_LIBRARIES=1 \
  cargo build --release --all-features
  local _completion="target/release/onefetch --generate"
  $_completion bash > "completions/onefetch"
  $_completion fish > "completions/onefetch.fish"
  $_completion zsh  > "completions/_onefetch"
}

check() {
  cd "$_realname-$pkgver"
  cargo test --frozen --all-features
}

package() {
  cd "$_realname-$pkgver"
  install -Dm 755 "target/release/$_realname" "${pkgdir}${MINGW_PREFIX}/bin/$_realname.exe"
  install -Dm 644 README.md -t "${pkgdir}${MINGW_PREFIX}/share/doc/$_realname"
  install -Dm 644 LICENSE.md -t "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname"
  install -Dm 644 "docs/$_realname.1" "${pkgdir}${MINGW_PREFIX}/share/man/man1/$_realname.1"
  install -Dm 664 "completions/onefetch" -t "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/"
  install -Dm 664 "completions/onefetch.fish" -t "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/"
  install -Dm 664 "completions/_onefetch" -t "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/"
}
